/*******************************************************************************
  * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.
  * @file     bsp.h
  * @author   UartTFT Application Team
  * @version  V0.0.1
  * @date     2023-01-04
  * @brief    This file contains the functions prototypes for the UartTFT
  *           Application display firmware.
 ********************************************************************************/

#ifndef _BSP_H
#define _BSP_H

#include "uart.h"
#include "qr_encode.h"
#include "function.h"
#include "module_select.h"
#include "w25qxx.h"
#include "w25n01.h"
#include "GBK.h"
#include "eflash.h"
//#include "pit32_drv.h"

extern void JiYi_ok(void);



#define MAIN_BUFF		0
#define LAY_BUFF1		0
#define LAY_BUFF2		0
#define LAY_BUFF3		0
#define LAY_BUFF4		0
#define LAY_BUFF5		0
#define LAY_BUFF6		0
#define LAY_BUFF7		0
#define LAY_BUFF8		0
#define LAY_BUFF9		0
#define LAY_BUFF10		0	
#define LAY_BUFF11		0
#define LAY_BUFF12		0
#define LAY_BUFF15		0
#define slideMune_BUFF	0


extern uint8_t ccs_sck_dv;
extern uint16_t css_res_time;
extern uint8_t css_write_test;
extern uint32_t RAM_display_addr;
extern uint32_t Display_Layer;
extern uint8_t Flash_type;

/*ModBus operating variables*/
extern uint16_t Cnt_ModbusTX;
extern uint16_t Sum_ModbusTX;

/*picture information*/
extern uint8_t pic_update;
extern uint8_t download_flag;

extern uint16_t pic_id;
extern uint16_t pic_id_temp;
extern uint32_t pic_add;
extern uint16_t pic_w;
extern uint16_t pic_h;
extern uint32_t pic_len;
extern uint8_t pic_flag;

/*Variable space*/
//extern uint8_t *var;
extern uint8_t var[];
extern uint8_t var_temp[];
extern uint8_t config_buff[];
extern uint8_t config_buff_overlay[];
extern uint16_t data_w;
extern uint8_t Display_buff[STRLEN_SIZE];
extern uint8_t Display_buff_temp[];

extern uint8_t g_upbuffer[];		// updata mcu buffer 4k
extern uint8_t g_upflag;		    //

/*backlight information*/
extern uint16_t gDutyBuf[];
extern uint8_t Auto_Backlight;
extern uint32_t Backlight_count;
extern uint8_t Backlight_flag;
extern uint8_t Backlight_touch;
extern uint8_t Backlight_time;

/*configuration parameter variable*/
extern uint8_t buzzer;
extern uint16_t Start_page;
extern uint8_t SCI_C0;
extern uint8_t SCI_C1;
extern uint8_t CRC_Enable_Flag;
extern uint8_t CRC_Feedback_Flag;
extern uint8_t parity_flag;	//CJC
extern uint8_t Screen_DIR;
extern uint8_t TFT_bitcolor;
extern uint8_t multi_language;
extern uint8_t multi_language_count;
extern uint8_t UI_update;

/*touch public*/
extern uint8_t button_Press_flag;
extern uint8_t buzzer_start;
extern uint8_t buzzer_10ms_count;
extern uint8_t Button_Key_Code_Flag;
extern uint16_t Button_Key_Code;

/*volume*/
extern uint8_t wav_reduce_para;

extern uint8_t pdata_D_num;

extern uint8_t Count_sum;
extern uint8_t Count_flag;
extern uint8_t Record_count;
extern uint16_t Count_reg[8]; 
extern uint8_t Count_reg_num;

extern uint8_t data_D_num;
extern uint16_t data_D_w[DATA_WLEN_SIZE];
extern uint16_t data_w;


extern uint16_t pdata_D_w[DATA_WLEN_SIZE];

extern uint8_t knob_flag;

extern uint8_t lt_screen_dir;

//----------------others module---------------------
void BackLight_control(void); 		// backlight
void LT_LCD_screen_dir(uint8_t dir); // screen_dir

void touch_buzzer(void); 			// touch buzzer

extern uint32_t GetCrc32(uint8_t *InStr,uint32_t len,uint32_t value);
uint32_t LtPow(uint16_t d, uint16_t n);
extern void APP(uint32_t appxaddr);           // application jump

uint8_t CoordinateChangeToBox(int16_t *x, int16_t *y, int16_t *w, int16_t *h, uint8_t alignment, _PICINFO pic, uint8_t mix);
void Var_AddrRemapping(uint16_t *addr);
void Var_AddrToReg(uint8_t *buf);
void reg_operation(uint16_t addr); // reg operation

extern void Display_page(uint16_t id);
extern void Display_pop_up(uint16_t id, uint16_t x, uint16_t y);
void download_page(uint16_t id, uint8_t direction);

uint16_t LT_Print_zk_Font(
uint16_t encode // encoding type     0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII  6:UNICODE
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size // font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	,
	uint8_t mix // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	,
	_PICINFO mixpic // mix picture info
	,
	uint8_t text_mode // text display mode: 0:txt  1:encryption use '*' (0x2A)
	,
	uint16_t Xs // Text box start x position
	,
	uint16_t Ys // Text box start Y position
	,
	uint16_t Xe // Text box end x position
	,
	uint16_t Ye // Text box end y position
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
);

uint16_t LT_Print_zk_Font_BUFF(
	uint16_t encode // encoding type     0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII  6:UNICODE
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size // font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	//,uint16_t mix                 // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	//,_PICINFO mixpic                    // mix picture info
	,
	uint8_t text_mode // text display mode: 0:txt  1:encryption use '*' (0x2A)
	,
	uint16_t buf_w // width of buffer
	,
	uint16_t buf_h // height of buffer
	,
	uint8_t *buf // address of buffer
	,
	uint16_t buf_x // start x of buffer
	,
	uint16_t buf_y // start y of buffer
	,
	uint16_t text_W
	,
	uint16_t text_H
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
);

uint16_t LT_Print_zk_Font_Scroll(
	uint16_t encode // encoding type     0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII  6:UNICODE
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size //  font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	,
	uint8_t mix // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	,
	_PICINFO mixpic // mix picture info
	,
	uint16_t Xs // Text box start x position
	,
	uint16_t Ys // Text box start Y position
	,
	uint16_t Xe // Text box end x position
	,
	uint16_t Ye // Text box end y position
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
	,
	uint8_t num // Scroll_num
	,
	uint16_t x_off // x offset
);

//-------------------------------------Variable area of function----------------------------------------------------------------------------
uint8_t LT268_buffer_pixel_blending(uint16_t *dst_p,uint16_t *src_p,uint8_t Cflag);


uint8_t Check_UIHead(void);
void ckeck_UI(void);
void WDT_Init(void);
void WDT_FeedDog(void);
#endif /* _BSP_H */

